﻿Imports CRM.BusinessLayer
Partial Public Class frmCompleteEvent
    Public EventId As Long
    Public caseid As Long
    Public RepeatEvent As Boolean

    Private Sub btnComplete_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnComplete.Click
        Dim LinkId As Long = 0
        Dim LinkType As TasksEvents.EventTypes = 0
        Dim tsk As New CRM.BusinessLayer.TasksEvents
        Try


            If Me.txtNotes.Text.Trim = String.Empty Then
                CommonFuncs.DisplayMessage("You must provide a completion note", CommonDialog.CustomDialogIcons.Information, "Note")
                Exit Sub
            End If

            If tsk.DismissEvent(EventId, GlobalCRM.CurrentConID, Me.txtNotes.Text, LinkId, LinkType) Then
                'Dismissed OK, flag that we should ask for a repeat
                Me.RepeatEvent = True
                Me.Close()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmCompleteEvent_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp
        If e.Key = Key.Escape Then
            btnCancel_Click(sender, e)
        End If
    End Sub

    Private Sub frmCompleteEvent_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        If Me.EventId = 0 Then
            CommonFuncs.DisplayMessage("Event ID Not Set, Contact IT", CommonDialog.CustomDialogIcons.Information, "Event ID")
            Me.Close()
            Exit Sub
        End If
        txtNotes.Focus()
    End Sub

    Private Sub btnSendEmail_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSendEmail.Click
        Dim frmSendEmail As New frmSendEmail
        Dim tsk As New TasksEvents
        Try


            Dim strinfo As String
            If GlobalCRM.CurrentCompanyID = 0 Then
                strinfo = "Candidate"
            Else
                If GlobalCRM.CurrentContactID > 0 Then
                    If MsgBox("Would you like to reply back to contact? Selecting 'No' would send a reply to candidate.", MsgBoxStyle.YesNo, "Company Email") = MsgBoxResult.Yes Then
                        strinfo = "Contact"
                    Else
                        strinfo = "Candidate"
                    End If
                Else
                    strinfo = "Candidate"
                End If
            End If
            Select Case strinfo
                Case "Blank"
                    frmSendEmail.iEmailType = CommonDataFunctions.EmailType.Blank
                Case "Candidate"
                    frmSendEmail.iEmailType = CommonDataFunctions.EmailType.Candidate
                Case "Contact"
                    frmSendEmail.iEmailType = CommonDataFunctions.EmailType.Contact
                Case "Both"
                    frmSendEmail.iEmailType = CommonDataFunctions.EmailType.Both
            End Select
            'copy history of the event
            Dim myEvent As TasksEvents.EventInfo = tsk.GetEvent(EventId)
            Dim range As TextRange
            With myEvent
                range = New TextRange(frmSendEmail.txtbody.Document.ContentStart, frmSendEmail.txtbody.Document.ContentEnd)
                range.Text = vbCrLf & vbCrLf & vbCrLf & vbCrLf & "----------------------Reply Separator--------------------------" & vbCrLf & vbCrLf & .Message
                'frmSendEmail.txtSubject.Text = .Description
            End With
            CommonFuncs.AddRegValue(Me.caseid)
            frmSendEmail.emailEvent = EventId
            'frmSendEmail.MdiParent = frmMDIMain
            frmSendEmail.Show()
            Me.Close()
        Catch ex As Exception
        Finally
            tsk = Nothing
            frmSendEmail = Nothing
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class
